<?php
/**
 * clickandbook
 * 
 * @package Config 
 */

/**
 * Retrieve configuration
 * 
 * @author Arno Schneider arnoschn at gmail.com
 */
class Config
{
	private static $_inited = false;
	private static $_ini = array();
	
	/**
	 * initialize the config
	 *
	 */
	private static function _init()
	{
		if (!self::$_inited) {
			self::$_ini = include CONFIG_DIR  . 'config.php';
			if (!is_array(self::$_ini)) {
				self::$_ini = array();
			}
			self::$_inited = true;
		}
	}
	
	/**
	 * set the value of a section/name
	 *
	 * @param string $section
	 * @param string $name
	 * @param mixed $value
	 */
	public static function set($section, $name, $value) {
		self::_init();
		if (!isset(self::$_ini[$section])) {
			self::$_ini[$section] = array();
		}
		self::$_ini[$section][$name] = $value;
	}
	
	public static function notEmpty($section, $name)
	{
		self::_init();
		$val = self::get($section, $name);
		return !empty($val);
	}
	
	public static function isEmpty($section, $name)
	{
		self::_init();
		$val = self::get($section, $name);
		return empty($val);
	}
	
	/**
	 * Retrieve a configuration value
	 *
	 * @param string $section
	 * @param string $name
	 * @return mixed value of the section/name entry or false if not exists
	 */
	public static function get($section, $name)
	{
		self::_init();
		if (isset(self::$_ini[$section])) {
			if (isset(self::$_ini[$section][$name])) {
				return self::$_ini[$section][$name];
			}
			return false;
		}
		return false;
	}
}